package com.property.web.controller.management;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.property.common.annotation.Log;
import com.property.common.enums.BusinessType;
import com.property.management.domain.CourtInfo;
import com.property.management.service.ICourtInfoService;
import com.property.common.core.controller.BaseController;
import com.property.common.core.domain.AjaxResult;
import com.property.common.utils.poi.ExcelUtil;
import com.property.common.core.page.TableDataInfo;

/**
 * 小区信息Controller
 * 
 * @author property
 * @date 2021-05-06
 */
@Controller
@RequestMapping("/property/court")
public class CourtInfoController extends BaseController
{
    private String prefix = "property/court";

    @Autowired
    private ICourtInfoService courtInfoService;

    @RequiresPermissions("property:court:view")
    @GetMapping()
    public String court()
    {
        return prefix + "/court";
    }

    /**
     * 查询小区信息列表
     */
    @RequiresPermissions("property:court:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(CourtInfo courtInfo)
    {
        startPage();
        List<CourtInfo> list = courtInfoService.selectCourtInfoList(courtInfo);
        return getDataTable(list);
    }

    /**
     * 导出小区信息列表
     */
    @RequiresPermissions("property:court:export")
    @Log(title = "小区信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(CourtInfo courtInfo)
    {
        List<CourtInfo> list = courtInfoService.selectCourtInfoList(courtInfo);
        ExcelUtil<CourtInfo> util = new ExcelUtil<CourtInfo>(CourtInfo.class);
        return util.exportExcel(list, "小区信息数据");
    }

    /**
     * 新增小区信息
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存小区信息
     */
    @RequiresPermissions("property:court:add")
    @Log(title = "小区信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(CourtInfo courtInfo)
    {
        return toAjax(courtInfoService.insertCourtInfo(courtInfo));
    }

    /**
     * 修改小区信息
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Integer id, ModelMap mmap)
    {
        CourtInfo courtInfo = courtInfoService.selectCourtInfoById(id);
        mmap.put("courtInfo", courtInfo);
        return prefix + "/edit";
    }

    /**
     * 修改保存小区信息
     */
    @RequiresPermissions("property:court:edit")
    @Log(title = "小区信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(CourtInfo courtInfo)
    {
        return toAjax(courtInfoService.updateCourtInfo(courtInfo));
    }

    /**
     * 删除小区信息
     */
    @RequiresPermissions("property:court:remove")
    @Log(title = "小区信息", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(courtInfoService.deleteCourtInfoByIds(ids));
    }

    @PostMapping("/getCourtList")
    @ResponseBody
    public AjaxResult getCourtList(){
        return AjaxResult.success(courtInfoService.selectCourtInfoList(new CourtInfo()));
    }
}
